from MY_ECShop.common.base import create_browser, Base, create_loading_browser
import time
# 封装类
class PageGoods(Base):

    url = 'http://localhost:8080/ecshop/admin/index.php'
    menu_frame = 'menu-frame'  # menu-frame
    main_frame = "main-frame"  # main-frame
    goods_management = ('xpath', "//div[@id='menu-list']/ul/li[2]")
    add_menu = ('link text', "添加新商品")
    # 添加页面的元素的定位编写
    goods_name = ('name','goods_name')  # 商品名称

    font_style = ('name', 'goods_name_style')    # 有下拉框待解决 字体样式

    goods_num = ('name','goods_sn') # 商品货号
    goods_class= ('name','cat_id')  # 商品分类
    add_goods = ('xpath','//table[@id="general-table"]/tbody/tr[3]/td[2]/button')   # 添加分类
    input_extend = ('xpath','//table[@id="general-table"]/tbody/tr[3]/td[2]/span[1]/input')  # 输入自定义分类
    '/html/body/div[3]/div[2]/form/table[1]/tbody/tr[3]/td[2]/button'
    click_extend =('xpath','//table[@id="general-table"]/tbody/tr[3]/td[2]/span[1]/button')       # 确认分类
    extend = ('class name','button btn-def')# 扩展分类
    extend_class=('name','other_cat[]')     # 扩展选择分类
    commodity_brand = ('name','brand_id')   # 商品品牌
    add_brand = ('xpath','//table[@id="general-table"]/tbody/tr[5]/td[2]/button')     # 点击添加品牌   需要重新定位,元素重了
    input_brand = ('xpath','//table[@id="general-table"]/tbody/tr[5]/td[2]/span/input')        # 输入品牌名称
    onclick = ('xpath','//table[@id="general-table"]/tbody/tr[5]/td[2]/span/button')  # 点击确定
    supplier = ('name','suppliers_id')  # 有下拉框还未选择
    shop_price = ('name','shop_price')   # 本店售价
    user_name_price = ('id','rank_1') # 会员价格的注册用户
    user_sale_price = ('id','rank_3')     # 会员代销用户
    vip_price = ('id','rank_2')   # 会员vip
    number = ('name','volume_number[]')     # 优惠数量
    price = ('name','volume_price[]')       # 优惠价格
    market_price = ('name','market_price')  # 市场售价
    sales_num=('name','virtual_sales')  # 虚拟销量
    give_integral = ('name','give_integral')    # 赠送消费积分数
    give_integral_rade = ('name','rank_integral')   # 赠送等级积分数
    buy_integral = ('name','integral')  # 积分购买金额
    checkbox = ('name','is_promote')    # 勾选促销价
    checkbox_price = ('name','promote_price')   # 勾选促销价后输入价格,只能在勾选促销价之后输入
    auto_thumb = ('id','auto_thumb')      # 点击自动生成商品缩略图
    # 点击确认
    search_click = ("xpath",'//div[@class="button-div"]/input[2]')

    # 进入网页

    def page_goods_open_web(self):
        self.base_open_web(self.url)

    # 进入menu-iframe
    def page_goods_into_menu_iframe(self):
        self.base_name_iframe_window(self.menu_frame)

    # 进入main-iframe
    def page_goods_into_main_iframe(self):
        self.base_name_iframe_window(self.main_frame)

    # 退出menu-frame 或 main-frame
    def page_goods_quit_iframe(self):
        self.base_quit_all_iframe()

    # 定位添加商品
    def page_goods_click_add_menu(self):
        self.base_click(self.add_menu)

    # 点击商品管理
    def page_goods_click_management(self):
        self.base_click(self.goods_management)

    # 输入商品名称
    def page_goods_input_goods_name(self,message_input):
        self.base_input_massage(self.goods_name,message_input)

    # 字体样式
    def page_goods_font_style(self,option_number):
        self.base_drop_down_menu(self.page_goods_font_style, option_number)

    # 商品货号
    def page_goods_num(self,message_input):
        self.base_input_massage(self.goods_num,message_input)

    # 商品分类
    def page_goods_class(self,option_number):
        self.base_drop_down_menu(self.goods_class,option_number)

    # 添加分类
    def page_add_goods(self):
        self.base_click(self.add_goods)

    # 输入自定义分类
    def page_input_extend(self,message_input):
        self.base_input_massage(self.input_extend, message_input)

    # 点击确认添加自定义分类
    def page_click_extend(self):
        self.base_click(self.click_extend)

    # 点击添加扩展分类
    def page_extend(self):
        self.base_click(self.page_extend)

    # 下拉框选择分类
    def page_extend_class(self,option_number):
        self.base_drop_down_menu(self.extend_class,option_number)

    # 选择商品品牌
    def page_commodity_brand(self,option_number):
        self.base_drop_down_menu(self.commodity_brand,option_number)

    # 点击添加品牌按钮
    def page_add_brand(self):
        print(self.base_click(self.add_brand))

    # 自定义品牌名称
    def page_input_brand(self,message_input):
        self.base_input_massage(self.input_brand, message_input)

    # 确定自定义品牌
    def page_onclick(self):
        self.base_click(self.onclick)

    # 选择供货商
    def page_supplier(self,option_number):
        self.base_drop_down_menu(self.supplier,option_number)

    # 本店售价
    def page_shop_price(self,message_input):
        self.base_input_massage(self.shop_price,message_input)

    # 会员价格-注册用户
    def page_user_name(self,message_input):
        self.base_input_massage(self.user_name_price,message_input)

    # 代销用户
    def page_user_sale(self,message_input):
        self.base_input_massage(self.user_sale_price,message_input)

    # vip
    def page_vip(self,message_input):
        self.base_input_massage(self.vip_price,message_input)

    # 商品优惠数量
    def page_number(self,message_input):
        self.base_input_massage(self.number,message_input)

    # 优惠价格
    def page_price(self,message_input):
        self.base_input_massage(self.price,message_input)

    # 市场售价
    def page_market_price(self,message_input):
        self.base_input_massage(self.market_price,message_input)

    # 虚拟销量
    def page_sales_num(self,message_input):
        self.base_input_massage(self.sales_num,message_input)

    # 赠送消费积分数
    def page_give_integral(self,message_input):
        self.base_input_massage(self.give_integral,message_input)

    # 赠送等级积分数
    def page_give_integral_rade(self,message_input):
        self.base_input_massage(self.give_integral_rade,message_input)

    # 积分购买金额
    def page_buy_integral(self,message_input):
        self.base_input_massage(self.buy_integral,message_input)

    # 自动生成商品缩略图
    def page_auto_thumb(self):
        self.base_click(self.auto_thumb)

    # 点击确定
    def page_search_click(self):
        self.base_click(self.search_click)
        time.sleep(10)


    """关闭网页"""
    def page_goods_quit_web(self):
        self.base_quit_web()


if __name__ == '__main__':
    my_browser = create_loading_browser('yuan_jun')  # 创建浏览器对象
    goods_object = PageGoods(my_browser)  # 创建商品页面对象
    goods_object.page_goods_open_web()  # 打开后台端
    goods_object.page_goods_into_menu_iframe()#进入menu-frame
    goods_object.page_goods_click_management()  # 点击商品管理
    goods_object.page_goods_quit_iframe()
    goods_object.page_goods_into_main_iframe()
    time.sleep(6)





